package com.huluobo.mvvmdemo1903a.mvp.view;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.huluobo.mvvmdemo1903a.R;
import com.huluobo.mvvmdemo1903a.mvp.model.User;
import com.huluobo.mvvmdemo1903a.mvp.presenter.LoginPresenter;

/**
 * Created by lc on 2021/11/22.
 */
public class MvpLoginActivity extends AppCompatActivity implements IMvpLoginView {
    private EditText userNameEt, passwordEt;
    private LoginPresenter loginPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mvc_login);

        userNameEt = findViewById(R.id.user_name_et);
        passwordEt = findViewById(R.id.password_et);

        Button loginBtn = findViewById(R.id.login_btn);

        loginPresenter = new LoginPresenter(this);
        loginBtn.setOnClickListener(view -> loginPresenter.login());
    }

    @Override
    public String getUserName() {
        return userNameEt.getText().toString();
    }

    @Override
    public String getPassword() {
        return passwordEt.getText().toString();
    }

    @Override
    public void onLoginResult(Boolean isLoginSuccess) {
        if (isLoginSuccess) {
            Toast.makeText(this, getUserName() + "登录成功", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "登录失败", Toast.LENGTH_SHORT).show();
        }
    }
}
